package com.hanshunping.oop.encap;

import org.w3c.dom.ls.LSOutput;

public class AccountTest {
    public static void main(String[] args) {
        Account zfq = new Account("张",5,"123");
        System.out.println("name=" + zfq.getName());
    }

}
class Account {
    private String name;
    private double balance;
    private String password;

    public Account(String name, double balance, String password) {
//        this.name = name;
//        this.balance = balance;
//        this.password = password;
        this.setName(name);
        this.setBalance(balance);
        this.setPassword(password);
    }

    public String getName() {
        return name;
    }

    public double getBalance() {
        return balance;
    }

    public String getPassword() {
        return password;
    }

    public void setName(String name) {
        if(name.length() == 2 || name.length() == 3 || name.length() == 4) {
            this.name = name;
        }else{
            System.out.println("你输入的姓名信息有误，所以默认名字为无名");
            this.name = "无名";
        }
    }

    public void setBalance(double balance) {
        if(balance > 20) {
            this.balance = balance;
        }else{
            System.out.println("你输入的余额有误，默认值为100");
            this.balance = 100;
        }
    }

    public void setPassword(String password) {
        if(password.length() == 6) {
            this.password = password;
        }else {
            System.out.println("你输入的密码位数有误，默认为123456");
            this.password = "123456";
        }
    }
}
